package com.insta.playdroid;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

public class MainActivity extends TabActivity {

	private TabHost tabHost;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);
		tabHost = getTabHost();

		addTab(getString(R.string.album), R.drawable.album,
				AlbumActivity2.class);
		addTab(getString(R.string.song), R.drawable.songs, SongsActivity2.class);
		addTab(getString(R.string.artist), R.drawable.artist,
				ArtistActivity2.class);
		addTab(getString(R.string.playlist), R.drawable.playlist,
				PlayListActivity.class);
	}

	private void addTab(String label, int drawableId, Class<?> activite) {
		Intent intent = new Intent(this, activite);
		intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
		TabHost.TabSpec spec = tabHost.newTabSpec(label);

		View tabIndicator = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator, getTabWidget(), false);
		TextView title = (TextView) tabIndicator.findViewById(R.id.title);
		title.setText(label);
		ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
		icon.setImageResource(drawableId);

		spec.setIndicator(tabIndicator);
		spec.setContent(intent);
		tabHost.addTab(spec);
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		this.finish();
	}

}
